#include <iostream>
using namespace std;

template<class T>
class Stack
{
public:
	Stack(size_t capacity = 4)
	{
		_array = (T*)malloc(sizeof(T) * capacity);
		if (nullptr == _array)
		{
			perror("malloc申请空间失败");
			return;
		}
		//_array = new T[capacity];

		_capacity = capacity;
		_size = 0;
		cout << "Stack(size_t capacity = 4)" << endl;
	}

	~Stack()
	{
		delete[] _array;
		_capacity = 0;
		_size = 0;
	}

	void push(const T& data);
private:
	T* _array;
	int _capacity;
	int _size;
};


// 声明和定义分离的写法 不建议分离到.h 和.cpp，会出现链接错误
// 要分离也是在 .h 中
template<class T>
void Stack<T>::push(const T& data)
{
	_array[_size++] = data;
}


int main()
{
	Stack<int> st1;
	Stack<double> st2;

	return 0;
}
